from celery import shared_task
import time
from celery import shared_task
import time, requests, json
from tools.baiduapi import bdapi
from tools.myredis import r
from tools.myjwt import mjwt
from tools.pay import AliPay

@shared_task
def cheduler_task(name):
   end = int(time.time())-600
   key = mjwt.decode()
   olist = r.sorted_times(key,0,end)
   for i in olist:
      res = AliPay.query_pay(i.decode())
      requests
      content = res.text
      #更新订单更新用户余额
      
@shared_task  
def bdcardmes():
    # 从redis list中获取10条信息
    # 调用百度api接口
    # 将结果存入redis
    # baidu_url_list与redis中的数据保持一致
    blist = r.list_lrange('baidu_url_list',0,10)
    print("获取卡证信息成功........")
    print(blist)
    if blist:
        for i in blist:
            picurl = i.decode()
            print("解码成功............")
            print(picurl)
            #调用百度api接口
            mes = bdapi.fontmessage(picurl)
            #存入redis {"name":"zs","code":"234234"}
            r.set_str(picurl,json.dumps(mes))
            r.list_del('baidu_url_list',picurl)
            
    print("调用百度api接口")

# celery -A dingxiang worker -l info -P eventlet
# celery -A dingxiang beat -l info